package org.dromara.admin.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 *  代扣模式: 蚂蚁链,周期扣,免押+周期扣
 */
@Getter
@AllArgsConstructor
public enum DeductionModeType {

    /**
     * 蚂蚁链
     */
    ANT_CHAIN("ANT_CHAIN", "蚂蚁链"),

    /**
     * 周期扣
     */
    CYCLE_DEDUCT("CYCLE_DEDUCT", "周期扣"),

    /**
     * 免押+周期扣
     */
    NO_DEPOSIT_CYCLE("NO_DEPOSIT_CYCLE", "免押+周期扣");

    /**
     * 存库用的值
     */
    private final String code;

    /**
     * 前端展示用
     */
    private final String info;

    /**
     * 根据 code 获取枚举
     */
    public static DeductionModeType getByCode(String code) {
        for (DeductionModeType type : values()) {
            if (type.getCode().equalsIgnoreCase(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("无效的类型代码: " + code);
    }

    /**
     * 根据 info 获取枚举
     */
    public static DeductionModeType getByInfo(String info) {
        for (DeductionModeType type : values()) {
            if (type.getInfo().equals(info)) {
                return type;
            }
        }
        throw new IllegalArgumentException("无效的类型: " + info);
    }
}
